/*
 * @(#)FreemarkerResult.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.result.template;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.nhncorp.lucy.web.helper.ServletHelper;

import com.nhncorp.usf.core.config.runtime.ResultPageInfo;
import com.nhncorp.usf.core.result.helper.FreemarkerConfigFactory;

import freemarker.template.Configuration;

/**
 * Freemarker template 를 결과페이지로 생성하는 {@link Result}.
 *
 * @author Web Platform Development Team
 */
@SuppressWarnings("serial")
public class FreemarkerResult extends AbstractTemplateResult {

    /**
     * @param resultPage ResultPageInfo
     * @param dataMap    Map
     * @throws Exception the Exception
     * @see com.nhncorp.usf.core.result.AbstractResult#execute(com.nhncorp.usf.core.config.runtime.ResultPageInfo, java.util.Map)
     */
    public void execute(ResultPageInfo resultPage, Map<String, Object> dataMap) throws Exception {
        Configuration configuration = FreemarkerConfigFactory.getConfiguration();
        HttpServletResponse response = ServletHelper.getResponse();
        response.setContentType(contentType + "; charset=" + getPageEncoding());

        setPageBufferSize(resultPage, response);

        String src = resultPage.getSrc();
        execute(resultPage,  dataMap, src, configuration, response);
    }
}
